Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Elegant and battle-tested validation library for type-safe input data for TypeScript
Elegant and battle-tested validation library for type-safe input data for TypeScript.
Data entering your application from the outside world should not be trusted without
validation and often is of the any
type, effectively disabling your type checker around
input values. It's an industry good practice to validate your expectations right at your
program's boundaries. This has two benefits: (1) your inputs are getting validated, and
(2) you can now statically know for sure the shape of the incoming data. Decoders help
solve both of these problems at once.
import { array, iso8601, number, object, optional, string } from 'decoders';
// Incoming data at runtime
const externalData = {
id: 123,
name: 'Alison Roberts',
createdAt: '1994-01-11T12:26:37.024Z',
tags: ['foo', 'bar'],
};
// Write the decoder (= what you expect the data to look like)
const userDecoder = object({
id: number,
name: string,
createdAt: optional(iso8601),
tags: array(string),
});
// Call .verify() on the incoming data
const user = userDecoder.verify(externalData);
// ^^^^
// TypeScript automatically infers this type as:
// {
// id: number;
// name: string;
// createdAt?: Date;
// tags: string[];
// }
npm install decoders
You must set strict: true
in your tsconfig.json
in order for type inference to work
correctly!
// tsconfig.json
{
"compilerOptions": {
"strict": true
}
}
Documentation can be found on https://decoders.cc.
There is a dedicated page in the docs that explains how to build your own decoders — it’s fun!
FAQs
Elegant and battle-tested validation library for type-safe input data for TypeScript
The npm package decoders receives a total of 9,656 weekly downloads. As such, decoders popularity was classified as popular.
We found that decoders demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.